<?php
// 本类由系统自动生成，仅供测试用途
class InfoAction extends CommonAction {
	public function _initialize(){
		parent::_initialize();
		$icdb = M('Infocategory');
		$infocate = $icdb->where(array('site_id' => __SITEID__))->select();
		$this->assign('infocate',$infocate);
	}
	
	
	
    public function index(){
		
		
		
		
		$this->daodb = D('Info');
		$this->initView();
		$this->daodb->_list($this->view, array('status' => 1,'site_id' => __SITEID__),'id desc');
		$this->display();
    }
	
	public function read(){
		$id=$this->_get('id');
		$info = M('info')->where(array('id' => $id))->find();
		$this->assign($info);
		$this->pagenav[1]['title'] = $info['title'];
		$this->display();
	}
	//问答
	public function question(){
		$map = array();
		$map['site_id'] = __SITEID__;
		$map['type'] = 'question';
		if($this->_get('cid')){
			$map['infocategory_id'] = $this->_get('cid');
			$this->infocategory_id = $map['infocategory_id'];
		}
		$this->assign('cid', $map['infocategory_id']);
		//查询当前类,以便前台显示面包屑导航
		$this->assign('curcate',M('Infocategory')->where(array('id' => $this->infocategory_id))->find());
		if($this->_get('hot')){
			$this->hot = $this->_get('hot');
			$hotorder = 'click desc,';
		}if($this->_get('new')){
			$this->new = $this->_get('new');
			
		}
		$this->daodb = D('Info'); 
		
		$this->initView();
		$this->daodb->_list($this->view, $map,$hotorder.'id desc',10);
	    $this->display();
	}
	//查看问答
	public function readquestion(){
		$id=$this->_get('id');
		$Infodb=D('Info');
		$info = $Infodb->alias('i')->join("left join __MEMBER__ as m on m.id=i.member_id")->field("i.*, m.nickname as uname, m.img_url as head")->where(array('i.id' => $id))->find();
		$Infodb->update_click($id,$this->memberInfo['id']);
		$this->assign($info);
		//回答列表
		
		$evdb = M('Info_ev');
		$answerList = $evdb->alias('ie')->join("left join __MEMBER__ as m on m.id=ie.member_id")->Field("ie.*,m.nickname as uname, m.img_url as head")->where(array('ie.info_id' => $id))->select();
		$this->assign('answerList', $answerList);
		$this->pagenav[1]['title'] = $info['title'];
		$this->display();
	}
}